{extend name='public/content'}
{block name="title"}
	商品详情
{/block}

{block name="body"}
	<div class="client"></div>
	<div class="layui-container">  
		{foreach($list as $key=>$vol)}
		  <div class="layui-row">
		    <div class="layui-col-xs6 ">
		      <div class="layui-row">
			    <div class="layui-col-xs3 ">
			     
			    </div>
			    <div class="layui-col-xs3 ">
			   	 <div class="layui-btn layui-btn-normal xuanzekefu"  data-uid="{$vol.uid}">选择：{$vol.username}</div>
			    </div>
			  </div>
		    </div>
		    <div class="layui-col-xs9 ">
		    </div>
		  </div>
	 	{/foreach}
	</div>
	/**发给谁
	<input type="" name="touid">	
	消息内容
	<input type="text" name="msg">

	<div class="xiaoxi">
		<div></div>
	</div>

<button class="fasongxiaoi">发送消息</button>
<button class="shifozaixiang">是否在线</button>
{/block}

{block name="script"}
<script type="text/javascript">
require(['jquery'], function () {
	let dom={
       base:"http://127.0.0.1/",
       soketbase:"ws://127.0.0.1:7272/",
    }
    let i=0;
    ws = new WebSocket(dom.soketbase);
    ws.onopen = onopen;
    ws.onmessage = onmessage;
      function onmessage(e){       
       let dat=e.data; 
      // console.log(dat);//return;
      let msg = $.parseJSON(dat);

        if(msg.type=="ping"){
        	return;
        }
        if(msg.type==1){
       		//绑定uid
       		$('.client').text(msg.cliet);	
       		$.ajax({
       			url: "{:url('work/binduidbyclient')}",
       			type: 'GET',
       			dataType: 'json',
       			data: {client: msg.cliet,uid:"{$userinfo.uid}"},
       		})
       		.done(function() {      			
       		})
       		.fail(function() {      			
       		})
       		.always(function() {      			 
       		});
       		
       }
       console.dir(dat);	
       if(msg.type==2){
       	    console.dir(msg);
       		$('.xiaoxi').append(msg.msg)

       }
     }
     
     function onopen(e){ 
     
     }

		 $('.fasongxiaoi').click(function() {
		 	let msg		 = $('input[name=msg]').val();
		 	let fromuid  = "{$userinfo.uid}";
		 	let touid    = $('input[name=touid]').val();
		 	$('.xiaoxi').append(msg);
		 	$.ajax({
		 		url: "{:url('index/work/sedmsuid')}",
		 		type: 'GET',
		 		dataType: 'json',
		 		data: {fromuid:fromuid,touid:touid,msg:msg,type:2,userinfo:'{$info}'},
		 	})
		 	.done(function() {
		 		
		 	})
		 	.fail(function() {
		 		
		 	})
		 	.always(function() {
		 		
		 	});
		 });

		$(".xuanzekefu").click(function(event) {
		 	let that =$(this);
		 	$('input[name=touid]').val(that.data('uid'));
		 	
		 	let sing = '{$userinfo.uid}'+that.data('uid');
		 	
		 	$.get('{:url("historicalrecord")}?sing='+sing, function(data) {
				let msglist = data.msg;
				$('.xiaoxi').text('');
				for (var i = msglist.length - 1; i >= 0; i--) {
					$('.xiaoxi').append(msglist[i].msg)
				}
			});	
		 });
		 $(".shifozaixiang").click(function(event) {
			var touid =$('input[name=touid]').val();
     	 $.ajax({
     		url: "{:url('index/work/isonline')}",
     		type: 'GET',
     		dataType: 'json',
     		data: {touid:touid},
     	 })
     	 .done(function($data) {
     		alert($data);
     	 })
     	 .fail(function() {
     		
     	 })
     	 .always(function() {
     		
     	 });
     });      
})
</script>
{/block}

{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}